<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        var obj1 = {
            name: 'andy',
            age: 19,
            sayHi: function () {
                console.log('say hi');
            }
        }

        var obj2 = {
            name: 'jack',
            age: 18,
            sayHi: function () {
                console.log('say hi');
            }
        }

        //可以通过函数 抽取相同的部分代码 封装到函数中
        // 工厂方法创建对象 
        function creatDemo(name, age) {
            var obj = {};

            obj.name = name;
            obj.age = age;

            return obj;
        }

        var obj3 = creatDemo('zs', 20);
        var obj4 = creatDemo('ls', 28);
        var obj5 = creatDemo('ww', 25);

        console.log(obj3, obj4);

    </script>
</body>

</html>